package com.qianbao.qianbaobusiness.ui.qrcode;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.baseandroid.config.Global;
import com.baseandroid.event.QrCodeShopSwitchEvent;
import com.baseandroid.mvp.BaseMvpActivity;
import com.qianbao.qianbaobusiness.R;
import com.qianbao.qianbaobusiness.ui.support.wechatprogram.SingleSwitchShopRvAdapter;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 小微进件选择店铺
 */
public class SwitchShopOfQrActivity extends BaseMvpActivity<SwitchShopOfQrView, SwitchShopOfQrPresent> {
    @BindView(R.id.tv_title)
    TextView     mTvTitle;
    @BindView(R.id.rv)
    RecyclerView mRv;
    private String mMerchantNo = "";
    private SingleSwitchShopRvAdapter mRvAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_wechat_switch_shop;
    }

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    @Override
    protected void setupView() {
        mMerchantNo = Global.getQrCardSelectedMerchantNo();
        mTvTitle.setText("切换门店");
    }

    @Override
    protected void setupData(Bundle savedInstanceState) {
        mRv.setLayoutManager(new LinearLayoutManager(this));
        if (mRvAdapter == null) {
            mRvAdapter = new SingleSwitchShopRvAdapter(this, mMerchantNo);
        }
        mRvAdapter.setOnClickListen(new SingleSwitchShopRvAdapter.ClickListen() {
            @Override
            public void click(String merchantNo) {
                EventBus.getDefault().post(new QrCodeShopSwitchEvent(merchantNo));
                finish();
            }
        });
        mRv.setAdapter(mRvAdapter);
        List list = Global.getShopListInfo().merchantList;
        mRvAdapter.resetData(list);
    }

    @OnClick(R.id.iv_back_toolbar)
    public void onViewClicked() {
        finish();
    }
}
